﻿using System.Linq;
using NRex;
using NRex.Logging;

namespace Codingly.NRex
{
    internal class AssemblyReferencesLister : AbstractReferencesLister
    {
        public AssemblyReferencesLister(ILogger logger)
            : base(logger)
        {
        }

        public void ProcessTarget(string fileOrDirectory)
        {
            GetAssemblies(fileOrDirectory);
            if (Assemblies.Count() == 0)
                return;

            PrintAssemblyReferences();
        }

        private void PrintAssemblyReferences()
        {
            foreach (var assembly in Assemblies)
            {
                Logger.Info("{0} references", assembly.GetName().Name);
                foreach (var referenced in assembly.GetReferencedAssemblies())
                {
                    Logger.Info("\tversion {1} of {0} ", referenced.Name, referenced.Version);
                }
            }
        }
    }
}